package mvpfoot.presenter;

import android.os.Environment;
import android.os.SystemClock;
import android.util.Log;


import mvpfoot.entity.Constant;
import mvpfoot.entity.UrlData;
import mvpfoot.entity.User;
import mvpfoot.entity.ZhiHuDaily;
import mvpfoot.ui.LoginActivity;
import mvpfoot.utils.MockService;
import okhttp3.internal.Util;


/**
 * Created by Chen qin lang on 2016/12/27.
 */
public class LoginPresenter extends BasePresenter {


    private static final String TAG ="basePresenter";
    public LoginActivity loginActivity;

    public LoginPresenter(LoginActivity loginActivity) {
        this.loginActivity = loginActivity;
    }

    public void login(String name, String pwd){
        Log.d(TAG, "login() called with: " + "name = [" + Constant.CACHE_FILE + "], pwd = [" + Environment.getExternalStorageDirectory() + "]");
        UrlData urlData = MockService.findUrl("Login");
        if (urlData!=null){
            //判断用户密码帐号是否正确
            //回调界面显示`
            if (urlData.getUsername().equals("cql")){
                User user = User.getInstance();
                user.setLoginStatus(true);
                user.setName(name);
                user.setScore(3000*1000);
                user.savaObject();
                loginActivity.register(name,pwd);

            }else{
                loginActivity.loaderror(name);
            }
        }
    }

    @Override
    public void pareseData(retrofit2.Response response) {
        ZhiHuDaily daliy = (ZhiHuDaily) response.body();
        String s = response.body().toString();
        Log.d(TAG, "pareseData() called with: " + "response = [" + daliy.getStories().get(0).getImages()+ "]");    }

    @Override
    public void showError() {

    }

}
